#include <boost/interprocess/shared_memory_object.hpp> 
#include <boost/interprocess/mapped_region.hpp> 
#include <iostream> 

int main() 
{ 
  boost::interprocess::shared_memory_object shdmem(boost::interprocess::open_or_create, "Liang", boost::interprocess::read_write); 
  shdmem.truncate(1024); 
  boost::interprocess::offset_t size;
	if ( shdmem.get_size(size) )
		std::cout << size << std::endl;

  boost::interprocess::mapped_region region(shdmem, boost::interprocess::read_write); 
  std::cout << std::hex << "0x" << region.get_address() << std::endl; 
  std::cout << std::dec << region.get_size() << std::endl; 
  int *i1 = static_cast<int*>(region.get_address());
  *i1 = 1212;

  boost::interprocess::mapped_region region2(shdmem, boost::interprocess::read_only); 
  std::cout << std::hex << "0x" << region2.get_address() << std::endl; 
  std::cout << std::dec << region2.get_size() << std::endl; 
  int *i2 = static_cast<int*>(region.get_address());
  std::cout << *i2 << std::endl;

  std::size_t page_size = boost::interprocess::mapped_region::get_page_size();
  std::cout << "page size: " << page_size << std::endl;
  bool removed = boost::interprocess::shared_memory_object::remove("Liang");
  std::cout << "removed: " << removed << std::endl;
  return 0;
} 